#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int c[N];
struct Line {
  int l, r;
  bool operator<(const Line& b) const { return r < b.r; }
} a[N];
int mn[N << 2], tag[N << 2];
void addtag(int d, int p) {
  mn[p] += d;
  tag[p] += d;
}
void pushup(int p) { mn[p] = tag[p] + min(mn[p << 1], mn[p << 1 | 1]); }
void build(int p, int l, int r) {
  tag[p] = 0;
  if (l == r) {
    mn[p] = c[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int L, int R, int d, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(d, p);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, d, p << 1, l, mid);
  if (R > mid) update(L, R, d, p << 1 | 1, mid + 1, r);
  pushup(p);
}
int query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return mn[p];
  int res = 1e9;
  int mid = (l + r) >> 1;
  if (L <= mid) res = min(res, query(L, R, p << 1, l, mid));
  if (R > mid) res = min(res, query(L, R, p << 1 | 1, mid + 1, r));
  return res + tag[p];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> c[i];
  rep(i, 1, m) cin >> a[i].l >> a[i].r;
  sort(a + 1, a + m + 1);
  int ans = 0;
  build(1, 1, n);
  rep(i, 1, m) {
    int x = query(a[i].l, a[i].r, 1, 1, n);
    if (x >= 1) update(a[i].l, a[i].r, -1, 1, 1, n), ans++;
  }
  cout << ans;
  return 0;
}